﻿#include <iostream>
#include <omp.h>

int global_var = 10;

int main() {
    int shared_var = 0;
    int loop_max = 100;

    // 正确用法：显式声明作用域
#pragma omp parallel default(none) shared(shared_var, global_var, loop_max)
    {
        int private_var = omp_get_thread_num();
#pragma omp critical
        {
            shared_var += 1;
            global_var += private_var;
        }
    }

    std::cout << "结果: shared_var = " << shared_var
        << ", global_var = " << global_var << std::endl;
    return 0;
}